package com.xuecheng.teaching.controller;

import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.dto.WorkCorrectDto;
import com.xuecheng.commons.model.dto.WorkRecordDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.WorkCorrectVo;
import com.xuecheng.commons.model.vo.WorkCountVo;
import com.xuecheng.commons.model.vo.WorkRecordVo;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.teaching.service.WorkRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 作业提交记录前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class WorkRecordController {

    @Autowired
    private WorkRecordService  workRecordService;

    //提交答案
    @PostMapping("/work-record")
    public ResponseResult submitAnswer(@RequestBody WorkRecordDto workRecordDto){
        return workRecordService.submitAnswer(workRecordDto);
    }

    //分页+条件查询
    @PostMapping("/work-record/list")
    public ResponseResult<WorkRecordVo> findByPage(PageRequest pageRequest,@RequestBody(required = false)String courseName ){
        return workRecordService.findByPage(pageRequest,courseName);
    }

    //分页查询提交的作业
    @PostMapping("/workpage/teachplan")
    public ResponseResult<WorkCorrectVo> workPage(PageRequest pageRequest,@RequestParam Long teachplanId	){
        return workRecordService.workPage(pageRequest,teachplanId);
    }

    //批改作业
    @PutMapping("/work-record/correction")
    public ResponseResult correctWork(@RequestBody WorkCorrectDto workCorrectDto){
        return workRecordService.correctWork(workCorrectDto);
    }

    //获取课程内包含的作业数
    @GetMapping("/getGroupNum")
    public ResponseResult<Integer> getGroupNum(Long coursePubId){
        return workRecordService.getGroupNum(coursePubId);
    }
}
